package servlet;

import dao.RegisterDateBase;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "registerServlet")
public class registerServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            request.setCharacterEncoding("UTF-8");
            response.setCharacterEncoding("UTF-8");
        String username=request.getParameter("username");
        Integer password=Integer.parseInt(request.getParameter("password"));
        RegisterDateBase registerDateBase=new RegisterDateBase();
        try {
            registerDateBase.addUser(username,password);
        } catch (Exception e) {
            e.printStackTrace();
        }
        request.getRequestDispatcher("/login.jsp").forward(request, response);
    }
}
